home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1995 June: Reference Library / Dev.CD Jun 95 / Dev.CD Jun 95.toast / What's New? / New System Software Extensions / QuickDraw 3D ß / Programming / SampleCode / Modeller ƒ / Modeller_utility.c < prev    next >
Encoding:
Text File  |  1995-03-06  |  1.9 KB  |  74 lines  |  [TEXT/MPS ]

  1. //
  2. //
  3. //        utility.c
  4. //
  5. //        Utility routines.
  6. //        
  7. //
  8. //        Author:        Rob Johnston
  9. //        Date:        Tuesday, January 14, 1992
  10. //
  11. //        Copyright © 1992-94 Apple Computer, Inc., All Rights Reserved
  12. //
  13. //
  14.  
  15.  
  16. #include "Modeller_prototypes.h"
  17.  
  18. #include "Modeller_utility.h"
  19. //
  20. //    PStrCmp returns true if the two given pascal strings are equal.
  21. //
  22.  
  23. short PStrCmp(char *s1, char *s2)
  24.  
  25. {    short        size, index;
  26.  
  27.     size = s1[0] + 1;
  28.  
  29.     while (size--) {
  30.         if (*(s1++) != *(s2++))
  31.             return(false);
  32.     }
  33.  
  34.     return(true);
  35. }
  36.  
  37.  
  38.  
  39.  
  40. //-------------------------------------------------------------------------------------------
  41. // Given two rectangles, this function positions the second within the first
  42. // one so that it maintains the spacing specified by the horzRatio and
  43. // vertRatio parameters.  In other words, to center an inner rectangle
  44. // hoizontally, but have its center be 1/3 from the top of the outer rectangle,
  45. // call this function with horzRatio = FixRatio(1, 2), vertRatio =
  46. // FixRatio(1, 3).  We use Fixed rather than floating point to avoid
  47. // complications when mixing MC68881/non-MC68881 versions of Utilities. 
  48.  
  49. void    PositionRectInRect(Rect *outerRect, Rect *innerRect, Fixed horzRatio, Fixed vertRatio)
  50. {
  51.     short    outerRectHeight;
  52.     short    outerRectWidth;
  53.     short    innerRectHeight;
  54.     short    innerRectWidth;
  55.     short    yLocation;
  56.     short    xLocation;
  57.  
  58.     outerRectHeight = outerRect->bottom - outerRect->top;
  59.     outerRectWidth = outerRect->right - outerRect->left;
  60.  
  61.     innerRectHeight = innerRect->bottom - innerRect->top;
  62.     innerRectWidth = innerRect->right - innerRect->left;
  63.         yLocation = Fix2Long(FixMul(Long2Fix(outerRectHeight - innerRectHeight), vertRatio))
  64.             + outerRect->top;
  65.         xLocation = Fix2Long(FixMul(Long2Fix(outerRectWidth - innerRectWidth), horzRatio))
  66.             + outerRect->left;
  67.  
  68.     innerRect->top = yLocation;
  69.     innerRect->left = xLocation;
  70.     innerRect->bottom = yLocation + innerRectHeight;
  71.     innerRect->right = xLocation + innerRectWidth;
  72. }
  73.  
  74.